// To be an activity in the app.. Will be modeled from AddPillActivity structure.

package com.pillpoppers.pillbox;

import java.util.ArrayList;

import com.pillpoppers.pillbox.database.Pill;
import com.pillpoppers.pillbox.database.PillboxDB;
import com.pillpoppers.pillbox.database.pillDB;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class SettingsActivity extends Activity implements OnClickListener
{
	private Button   btnClearData;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		setContentView(R.layout.activity_settings);
		
		super.onCreate(savedInstanceState);
		
		btnClearData = (Button) findViewById(R.id.resetDataButton);
		btnClearData.setOnClickListener(this);
		
	}
	
	@Override
    public void onClick(View v)
	{
		PillboxDB db = new PillboxDB(getApplicationContext());
		pillDB db2 = new pillDB(this);
		ArrayList<Schedule> als = new ArrayList<Schedule>();
		ArrayList<Contact> alc = new ArrayList<Contact>();
		ArrayList<Pill> alp = new ArrayList<Pill>();
		int numDeleted = 0;
		
		als = db.getSchedules();
		alc = db.getContacts();
		alp = db2.getPills();
		
		if (als != null)
		{
			for (int i = 0; i < als.size(); i++)
			{
				db.deleteSchedule(als.get(i).getScheduleId());
			}
		}
		
		if (alc != null)
		{
			for (int i = 0; i < alc.size(); i++)
			{
				db.deleteContact(alc.get(i).getContactID());
			}
		}
		
		if (alp != null)
		{
			for (int i = 0; i < alp.size(); i++)
			{
				db2.deletePill(alp.get(i).getPillID());
				numDeleted++;
			}
		}
		
		Toast t = Toast.makeText(this, "Database Cleared. " + numDeleted + " deleted.", Toast.LENGTH_SHORT);
		t.show();
		
		
    }

}
